package org.example.book.normal.state.order;

import org.example.book.normal.observe.DeprecatedAbstractObserver;

import java.util.List;
import java.util.Vector;

/**
 * @author jeff
 */
public abstract class DeprecatedOrderState {

    protected final String ORDER_WAIT_PAY = "ORDER_WAIT_PAY";
    protected final String ORDER_WAIT_SEND = "ORDER_WAIT_SEND";
    protected final String ORDER_WAIT_RECEIVE = "ORDER_WAIT_RECEIVE";
    protected final String ORDER_FINISH = "ORDER_FINISH";

    // 订单支付
    protected DeprecateOrder createOrder(String orderId, String productId, DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    // 订单发送
    protected DeprecateOrder sendOrder(String orderId, DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    // 订单签收
    protected DeprecateOrder receiveOrder(String orderId, DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    // 订单支付
    protected DeprecateOrder payOrder(String orderId, DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    protected final List<DeprecatedAbstractObserver> observerList = DeprecatedConstants.OBSERVERS;

    public void addObserver(DeprecatedAbstractObserver observer) {
        this.observerList.add(observer);
    }

    public void removeObserver(DeprecatedAbstractObserver observer) {
        this.observerList.remove(observer);
    }

    public void notifyObserver(String orderId, String orderState) {
        for (DeprecatedAbstractObserver deprecatedAbstractObserver : this.observerList) {
            deprecatedAbstractObserver.orderStateHandle(orderId, orderState);
        }
    }
}
